236C - LCM Challenge - CodeForces Solution


greedy number theory *1600

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <vector>

using namespace std;


long long gcd(long long a, long long b){

    if(a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b % a, a);
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long n; cin >> n;
    const int L = 100;

    vector<long long> v;
    for(int i = 0; i <= L && (n - i) >= 1; i ++) v.push_back(n - i);

    long long res = 0;
    for(int i = 0; i < v.size(); i ++)
        for(int j = i; j < v.size(); j ++)
            for(int k = j; k < v.size(); k ++){
                long long a = v[i] * v[j] / gcd(v[i], v[j]);
                long long b = a * v[k] / gcd(a, v[k]);
                res = max(res, b);
            }
    cout << res << '\n';

    return 0;
}


Comments

Submit
0 Comments
More Questions

1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words